﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cfg.ConfigProviders;
using NUnit.Framework;

namespace Cfg.Test.Transformers
{
    [TestFixture]
    public class Class1
    {
        public class Foo
        {
            public string X { get; set; }
            public string Y { get; set; }
        }

        public interface ITestConfig
        {
             Foo Foo { get; }
        }

        [Test]
        public void TestFoo()
        {
            AppSettings.Init<ITestConfig>();

            var cfg = AppSettings.Get<ITestConfig>();
            Console.WriteLine(cfg.Foo);
            
        }
    }

    [TestFixture]
    public class ArraysTest
    {
        public interface ITestConfig
        {
             IListItem[] Items { get; }
        }

        public interface IListItem
        {
             string Name { get; }
             int Value { get; }
        }

        public class TempProvider : IConfigFileProvider
        {
            public ConfigKeyValues GetValues()
            {
                return new ConfigKeyValues()
                    .Add("Items[0].Name", "Foo")
                    .Add("Items[0].Value", "1")
                    .Add("Items[1].Name", "Bar")
                    .Add("Items[1].Value", "2")
                    ;
            }
        }

        [Test]
        public void Test()
        {
            Cfg.AppSettings.Init<ITestConfig>(new TempProvider());

            var cfg = AppSettings.Get<ITestConfig>();

            Assert.AreEqual(2, cfg.Items.Length);
            Assert.AreEqual("Foo", cfg.Items[0].Name);
            Assert.AreEqual(1, cfg.Items[0].Value);
            Assert.AreEqual("Bar", cfg.Items[1].Name);
            Assert.AreEqual(2, cfg.Items[1].Value);
        }
    }

}
